toNonZeroIntOrNull

@ExperimentalSinceKotoolsTypes(version = "4.3.1")
fun Number.toNonZeroIntOrNull(): NonZeroInt?

Returns this number as a NonZeroInt, which may involve rounding or truncation, or returns null if this number equals zero.

var result: NonZeroInt? = 1.toNonZeroIntOrNull()
println(result) // 1

result = 0.toNonZeroIntOrNull()
println(null) // 0

You can use the toNonZeroIntOrThrow function for throwing an IllegalArgumentException instead of returning null when this number equals zero.